<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form binding="#{creditManagerBean.loadPayments}">
                    <p:panel header="Customer Details" id="customerDetailsPanel">
                        <table width="100%" border="0">
                            <tr>
                                <td width="200px">
                                    Company:
                                </td>
                                <td>
                                    <h:outputText id="company" value="#{creditManagerBean.selectedCustomer.company}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Description:
                                </td>
                                <td>
                                    <h:outputText id="description" value="#{creditManagerBean.selectedCustomer.description}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Annual Revenue:
                                </td>
                                <td>
                                    <h:outputText id="revenue" value="#{creditManagerBean.selectedCustomer.revenue}">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Number of Employees:
                                </td>
                                <td>
                                    <h:outputText id="numEmployee" value="#{creditManagerBean.selectedCustomer.numEmployee}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Contact Person
                                </td>
                                <td>
                                    <h:outputText id="contactPerson" value="#{creditManagerBean.selectedCustomer.firstName}, 
                                                  #{creditManagerBean.selectedCustomer.lastName}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Designation:
                                </td>
                                <td>
                                    <h:outputText id="title" value="#{creditManagerBean.selectedCustomer.title}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Contact Number:
                                </td>
                                <td>
                                    <h:outputText id="phone" value="#{creditManagerBean.selectedCustomer.phone}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Credit Rank:
                                </td>
                                <td>
                                    <h:outputText id="rank" value="#{creditManagerBean.selectedCustomer.credit.creditRank}" />
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">
                                    Credit Limit:
                                </td>
                                <td>
                                    <h:outputText id="limit" value="#{creditManagerBean.selectedCustomer.credit.creditLimit}">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <p:panel header="Payments" id="paymentsPanel">
                        <p:messages />
                        
                        <p:dataTable id="payments" var="payment" value="#{creditManagerBean.payments}" 
                                     emptyMessage="No payments found with given criteria."
                                     selection="#{creditManagerBean.selectedPayment}"
                                     selectionMode="single"
                                     onRowSelectUpdate="invoiceDetailsPanel,paymentDetailsPanel" 
                                     onRowUnselectUpdate="invoiceDetailsPanel,paymentDetailsPanel">
                            <p:column headerText="Payment Date" 
                                      sortBy="#{payment.paymentDate}">  
                                <h:outputText value="#{payment.paymentDate}"> 
                                    <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Payment Amount" sortBy="#{payment.amountPaid}">  
                                <h:outputText value="#{payment.amountPaid}">  
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Balance Used" sortBy="#{payment.balanceUsed}">  
                                <h:outputText value="#{payment.balanceUsed}">  
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Payment Status" sortBy="#{payment.status}">  
                                <h:outputText value="#{payment.status}">
                                </h:outputText>
                            </p:column> 
                        </p:dataTable>
                    </p:panel>
                    <p:panel header="Invoice Details" id="invoiceDetailsPanel">
                        <table width="100%" border="0">
                            <tr>
                                <td width="200px">Invoice ID:</td>
                                <td>
                                    <h:outputText id="invoiceId" 
                                                  value="#{creditManagerBean.selectedPayment.invoice.id}" 
                                                  title="ID of invoice.">
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Invoice Date:</td>
                                <td>
                                    <h:outputText id="invoiceDate" 
                                                  value="#{creditManagerBean.selectedPayment.invoice.invoiceDate}" 
                                                  title="Date of invoice.">
                                        <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Invoice Amount:</td>
                                <td>
                                    <h:outputText id="invoiceAmount" 
                                                  value="#{creditManagerBean.selectedPayment.invoice.amount}" 
                                                  title="Amount invoiced.">
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Invoice Type:</td>
                                <td>
                                    <h:outputText id="invoiceType" 
                                                  value="#{creditManagerBean.selectedPayment.invoice.type}" 
                                                  title="Type of invoice.">
                                    </h:outputText>
                                </td>
                            </tr>
                            <tr>
                                <td width="200px">Invoice Status:</td>
                                <td>
                                    <h:outputText id="invoiceStatus" 
                                                  value="#{creditManagerBean.selectedPayment.invoice.status}" 
                                                  title="Status of invoice.">
                                    </h:outputText>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                    <table class="table-submit">
                        <tr>
                            <td align="center">
                                                    <p:commandButton id="btnBackFromPayments" value="Back" 
                                     title="Go back to previous page."
                                     actionListener="#{creditManagerBean.back}"
                                     ajax="true"/>&nbsp;&nbsp;&nbsp;
                    <p:commandButton id="btnGoToViewInvoice" value="View Invoice Details" 
                                     title="View invoice details."
                                     actionListener="#{creditManagerBean.go}"
                                     update="paymentsPanel"
                                     ajax="true"/>
                            </td>
                        </tr>
                    </table>

                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
